/*$(function(){
	code();
	$("#login").click(function(){
		$.ajax({
				type:"POST",
				url:"user/userLogin",
				data:{
					userInfo:$("#studentLoginName").val(),
					userPass:$("#studentPass").val()
				},
				dataType:"json",
				success:function(data){
					if(data.STATUS=="1"){
						alert(data.MSG);
					}else{
						var input = data.userInput;
						if(data.error!=null&&data.error=="1"){
							$("#studentPass").val(input);
							$("#studentLoginName").val('');
						}else{
							$("#studentPass").val('');
							$("#studentLoginName").val(input);
						}
						$("#tip_span").html(data.MSG);
						setTimeout(function() {
							$("#tip_span").hide('fast');	
							$("#tip_span").html("");
							$("#tip_span").show('fast');	
						}, 2000);
//						alert("提示："+data.MSG);
					}
				},
				error:function(XMLHttpRequest, textStatus, errorThrown){
					$("#tip_span").html("there is something wrong!");
					alert(XMLHttpRequest.status);
				}
		});
	});
});*/

var reg_loginname = /^[a-zA-Z0-9_-]{6,12}$/;
	var reg_pass = /^[a-zA-Z0-9_-]{6,18}$/;
	$(function() {
		code();
		$("#studentLoginName").blur(function() {
			var username = $("#studentLoginName").val();
			if (username != ""&&username.length<2) {
					$("#loginName_span").html("&nbsp;&nbsp;输入姓名长度不符合要求");
			}
		});
		$("#studentLoginName").focus(function(){
            $("#loginName_span").html("");
		});$("#yzm").focus(function(){
            $("#ss").html("");
		});
	});
	function code() {
        $.ajax({
            type: "GET",
            url: "/eroly/ImgCode/getImageCodeBase64",
            dataType:"text",
            success: function (result) {
            	var obj = document.getElementById("imageCode");
                obj.src = "data:image/png;base64," + result;
            },
            error:function(data){
                alert(data);
            }
        });
	}

	function checkcode() {
        var valOfCode = $("#yzm").val();
        if(valOfCode==''){
            $("#ss").html("请输入验证码");
            $("#ss").css("color","red");
            return false;
        }
        if(valOfCode.length!=4){
            $("#ss").html("验证码为4位哦");
            $("#ss").css("color","red");
            return false;
        }
        $.ajax({
            type:"POST",
            url:"/eroly/ImgCode/checkImgCode",
            data:{
                iptCode:valOfCode
            },
            dataType:"json",
            success:function(data){
                if(data.STATUS=="1"){
                    return true;
                }else{
                    $("#yzm").val("");
                    $("#ss").html("验证码输入错误");
                    $("#ss").css("color","red");
                    code();
                    return false;
                }
            },
            error:function(errData){
                $("#yzm").val("");
                $("#ss").html("验证码输入错误");
                $("#ss").css("color","red");
                code();
                return false;
            }
        });
	}
	//点击登录验证
	function check() {
        if(checkcode()==false){
        	return false;
		}
		if ($("#studentLoginName").val() == "") {
			$("#loginName_span").html("请输入用户名!");
			$("#loginName_span").removeClass("okTip");
			$("#loginName_span").addClass("errorTip");
			return false;
		}

		if ($("#studentPass").val() == "") {
			$("#pass_span").html("请输入密码！");
			$("#pass_span").removeClass("okTip");
			$("#pass_span").addClass("errorTip");
			return false;
		} else {
			if (!reg_pass.test($("#password").val())) {
				$("#pass_span").html("密码格式为6-18位数字字母下划线");
				$("#pass_span").removeClass("okTip");
				$("#pass_span").addClass("errorTip");
				return false;
			}
		}
		var codecc = (document.getElementById("tsyzm").innerHTML).toLowerCase();
		var code = (document.getElementById("yzm").value).toLowerCase();
		if (code != "") {
			if (codecc != code) {
				document.getElementById("ss").innerHTML = "验证码输入错误"
				document.getElementById("ss").style.color = "red";
				return false;
			}
		} else {
			document.getElementById("ss").innerHTML = "请输入验证码！"
			document.getElementById("ss").style.color = "red";
			return false;
		}
		return true;
	}